package cn.zktr.Personnel.controllers.tantiantian;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.zktr.Personnel.model.pojos.PerPmsEmp;
import cn.zktr.Personnel.model.pojos.PerSlyScsy;
import cn.zktr.Personnel.model.pojos.PerSlySz;
import cn.zktr.Personnel.model.pojos.PerSlySzx;
import cn.zktr.Personnel.model.pojos.PerSlyTax;
import cn.zktr.Personnel.model.service.tantiantian.SlyScsyService;
import cn.zktr.Personnel.model.service.tantiantian.SlySetService;
import cn.zktr.Personnel.model.service.tantiantian.SlySzService;
import cn.zktr.Personnel.model.service.zhouyongcong.findService;
import cn.zktr.Personnel.model.uitls.Homapape;

@Controller
public class SocialSecurityAccountController {
		/**
		 * 社保套账
		 */
		@Autowired
		private SlySzService szser;
		/**
		 * 薪资套帐
		 */
		@Autowired
		private SlySetService slyser;
		/**
		 * 社保项目
		 */
		@Autowired
		private SlyScsyService scsySer;
		/**
		 * 员工
		 */
		@Autowired
		private findService findser;
		//社保套账
		@RequestMapping("ttt/social-security-account")
		public void SocialSecurityAccount(HttpSession session){
			//查询所有社保项目
			Iterable<PerSlyScsy> seleScsy=szser.seleScsy();
			session.setAttribute("seleScsy", seleScsy);
			
		}
		@RequestMapping("cial_shenhe")
		@ResponseBody
		public JSONArray cial_shenhe(HttpSession session) {
			return slyser.seleStmpotid(session);
		}
		/**
		 * @param page
		 * @param rows
		 * @return 查询所有社保套账
		 */
		@RequestMapping("SocialSecurityAccount_table")
		@ResponseBody
		public Map<String,Object> SocialSecurityAccount_table(int page,int rows,Model session,HttpSession sessions){
			//查询所有社保项目
			Iterable<PerSlyScsy> seleScsy=szser.seleScsy();
			session.addAttribute("seleScsy", seleScsy);
			//查询薪资员工上级，新资质部长
			JSONArray seleStmpotid=slyser.seleStmpotid(sessions);
			session.addAttribute("xinzibuzhang", seleStmpotid);
			
			Map<String,Object> map = new HashMap<>();
			map.put("total",szser.seleSzAll().size());
			Page<Object> p=PageHelper.startPage(page,rows);
			JSONArray findAll=szser.seleSzAll();
			//页内容
			map.put("rows",findAll);
			return map;
		}
		@RequestMapping("SecurityAccountTable")
		@ResponseBody
		public void SecurityAccountTable(PerSlySz sz,
				HttpSession session,
				String[] bianhao
				){
			//根据员工id查询员工信息
			PerPmsEmp emp = slyser.seleEmpids(7);
			sz.setPerPmsEmp1(findser.findEmpid(Integer.valueOf(session.getAttribute("id")+"")));
			sz.setPerPmsEmp2(emp);
			//新增社保套帐
			szser.AddSz(sz);
			List<PerSlyScsy> sc=new ArrayList<>();
			for(int i=0;i<bianhao.length-1;i++) {
				System.err.println(bianhao[i]);
				Optional<PerSlyScsy> scsy = szser.seleScsyid(Integer.parseInt(bianhao[i]));
				//给这包中间表添加值
				PerSlySzx szx=new PerSlySzx();
				szx.setPerSlyScsy(scsy.get());
				szx.setPerSlySz(szser.seleSzs());
				szser.addszx(szx);
			}
	
		}
		public JSONArray json;
		//社保套账查看sec_Byszid
		@RequestMapping("sec_Byszid")
		@ResponseBody
		public void sec_Byszid(Integer szid){
			 json=szser.sele_scsyByszid(szid);
		}
		@RequestMapping("acu_biao")
		@ResponseBody
		public JSONArray acu_biao(){
			return json;
			
		}
		//查询所有项目SecurityAccount_xiangmutables
		@RequestMapping("SecurityAccount_xiangmutables")
		@ResponseBody
		public JSONArray SecurityAccount_xiangmutables(){
			return szser.sele_scsyAll();
		}
		//根据套帐名称查询SocialSecurityAccount_table_name
		@RequestMapping("SocialSecurityAccount_table_name")
		@ResponseBody
		public JSONArray SocialSecurityAccount_table_name(String text){
			return szser.SocialSecurityAccount_table_name(text);
		}

}
